package net.com.bwie;

import cn.hutool.http.useragent.UserAgent;
import cn.hutool.http.useragent.UserAgentUtil;
import org.apache.hadoop.hive.ql.exec.UDF;

import java.util.HashMap;
import java.util.Map;

public class ParseUaToBrowser extends UDF {
    public Map<String,String> evaluate(String ua) throws Exception{
        HashMap<String, String> map = new HashMap<>();
        UserAgent uau = UserAgentUtil.parse(ua);
        map.put("os_version",uau.getOsVersion());
        map.put("os",uau.getOs().toString());
        map.put("engine_version",uau.getEngineVersion());
        map.put("engine",uau.getEngine().toString());
        map.put("version",uau.getVersion());
        map.put("browser",uau.getBrowser().toString());
        map.put("platform",uau.getPlatform().toString());
        map.put("is_mobile",uau.isMobile() ? "1" : "0");
        return map;
    }

    public static void main(String[] args) throws Exception{
        System.out.println(new ParseUaToBrowser().evaluate("Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 GTB5"));
    }
}
